/*
 * @Author: sky 11864026+jfcode81@user.noreply.gitee.com
 * @Date: 2025-09-18 17:54:01
 * @LastEditors: sky 11864026+jfcode81@user.noreply.gitee.com
 * @LastEditTime: 2025-10-17 10:19:00
 * @FilePath: \trading-center-pc\server\baseApi.ts
 * @Description: 基地管理相关接口与类型定义
 */
import { ItemObject, PageQuery } from '~/types/global'

/**
 * 基地管理相关接口
 */

/**
 * 获取基地分页列表
 * @param params 分页参数
 */
export const getBaseListApi = (params: PageQuery) => {
  return $request.get({ url: 'front/plantation/showList', params })
}

/**
 * 获取基地详情
 * @param id 基地ID
 */
export const getBaseDetailApi = (id: number) => {
  return $request.get({ url: `front/plantation/info/${id}` })
}

/**
 * 产品信息类型定义
 */
export interface ProductInfo {
  id: number
  baseId: number
  productName: string
}

/**
 * 基地信息类型定义
 */
export interface BaseInfo {
  id: number
  plantationName: string
  plantationManager?: number
  plantationManagerName?: string
  marketDate: string
  location: string
  description?: string
  plantingScale?: string
  plantingFacilities?: string
  mainProducts?: string | null
  features?: string | null
  contactPerson?: string
  contactPhone?: string
  contactEmail?: string
  transactionCode?: string | null
  imageUrl1?: string
  imageUrl2?: string
  videoUrl?: string
  qrCodeUrl?: string | null
  sort?: number
  status: boolean
  createTime?: string
  updateTime?: string
  // 兼容旧字段（如果服务端仍返回）
  baseName?: string
  featureTags?: string[]
  coverImage?: string
  products?: ProductInfo[]
  videos?: VideoInfo[]
  images?: string[]
}

/**
 * 基地列表响应类型
 */
export interface BaseListResponse {
  list: BaseInfo[]
  total: number
  page: number
  limit: number
  totalPage: number
}

/**
 * 视频信息类型定义
 */
export interface VideoInfo {
  id: number
  baseId: number
  videoName: string
  videoUrl: string
}

/**
 * 基地详情响应类型
 */
export interface BaseDetailResponse extends BaseInfo {
  // 可以添加更多详情字段
  images?: string[]
  videos?: VideoInfo[]
  facilities?: string[]
  coordinates?: {
    latitude: number
    longitude: number
  }
}

/**
 * 基地预约考察-保存接口 入参
 * 与后端文档保持一致
 * plantationId: 预约的种植基地ID
 * uid: 发起预约的用户ID（未登录传 0）
 * inspectionDays: 考察天数
 * companyName: 考察单位/个人姓名
 * purpose: 考察目的
 * numOfPeople: 预计同行人数
 * contactPhone: 联系电话
 */
export interface PlantationAppointmentSaveBody {
  plantationId: number
  uid: number
  inspectionDays: number
  companyName: string
  purpose: string
  numOfPeople: number
  contactPhone: string
}

/**
 * 基地预约考察-保存
 */
export const savePlantationAppointmentApi = (params: PlantationAppointmentSaveBody) => {
  return $request.post({ url: `front/plantation/appointment/save`, params })
}
